<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>某某家具设计公司企业官网-模板之家</title>
<link rel="stylesheet" href="layui/css/layui.css" />
</head>
<body>
	<jsp:include page="HeaderServlet"></jsp:include>
	
	<div>
    <header class="header-article-list">
        <h1>在线留言</h1>

    </header>
<div style="margin: auto;">
   <form class="layui-form" >

       <div class="layui-form-item" style="margin-left: 500px;">
				<label class="layui-form-label"><span style="color: red;">*</span>姓名</label>
				<div class="layui-input-inline">
					<input type="text" name="name" required lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>


       <div class="layui-form-item" style="margin-left: 500px;">
				<label class="layui-form-label"><span style="color: red;">*</span>电话</label>
				<div class="layui-input-inline">
					<input type="text" name="phone" required lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>


       <div class="layui-form-item" style="margin-left: 500px;">
				<label class="layui-form-label"><span style="color: red;">*</span>邮箱</label>
				<div class="layui-input-inline">
					<input type="text" name="email" required lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>


        <div class="layui-form-item" style="margin-left: 500px;">
				<label class="layui-form-label"><span style="color: red;">*</span>内容</label>
				<div class="layui-input-inline">
					<textarea type="text" name="body"></textarea>
				</div>
			</div>


      <div class="layui-form-item" style="margin-left: 500px;">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
   </form>
</div>
</div>
	<script type="text/javascript" src="layui/layui.js" ></script>
		<script>
			//加载了layui的form模块
			layui.use('form', function() {
				var form = layui.form;
				var $ = layui.jquery; //引入jquery
				//监听提交
				form.on('submit(formDemo)', function(data) {
					var d = data.field; //表单中的数据，定义一个对象来接收
					//通过ajax向数据库提交数据了
					d.method="add";
					console.log(d); //提交之前的一个数据验证、通过打印的方式先手动的去判断一下这个数据
					var url ='userServlet';
					//确保数据没有问题就进行ajax提交了
					$.post(url, d,
						function(data) {
							if(data.count>0){
								console.log('添加成功');
								var index=parent.layer.getFrameIndex(window.name); //获取当前窗口的name
             					 parent.layer.close(index);	//关闭窗口
             					window.location.reload();
							}
						}, "json");
					return false;
				});
			});
		</script>
	<jsp:include page="FooterServlet"></jsp:include>
</body>
</html>